﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lianxi1
{
    public partial class login : System.Web.UI.Page
    {
        public static List<Shop> shops = new List<Shop>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                shops.Clear();
                Shop s1=new Shop(){Shopid=1,Name="是",Leixing="leixing", Salary=30,Miaoshu="didi"};
                Shop s2 = new Shop() { Shopid = 2, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s3 = new Shop() { Shopid = 3, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s4 = new Shop() { Shopid = 4, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s5 = new Shop() { Shopid = 5, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s6 = new Shop() { Shopid = 3, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s7 = new Shop() { Shopid = 4, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s8 = new Shop() { Shopid = 5, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s9 = new Shop() { Shopid = 3, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s10 = new Shop() { Shopid = 4, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                Shop s11 = new Shop() { Shopid = 5, Name = "是", Leixing = "leixing", Salary = 30, Miaoshu = "didi" };
                
                shops.Add(s1);
                shops.Add(s2);
                shops.Add(s3);
                shops.Add(s4);
                shops.Add(s5);
                shops.Add(s6);
                shops.Add(s7);
                shops.Add(s8);
                shops.Add(s9);
                shops.Add(s10);
                shops.Add(s11);
                this.GridView1.DataSource = shops;
                this.GridView1.DataBind();
                
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString());
            Shop shanchu = new Shop();
            foreach (Shop item in shops)
            {
                if (id==item.Shopid)
                {
                    shanchu = item;
                    
                }
               
            }
            shops.Remove(shanchu);
            this.GridView1.DataSource = shops;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            this.GridView1.EditIndex = e.NewEditIndex;
            this.GridView1.DataSource = shops;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int id = Convert.ToInt32(((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
            foreach (var item in shops)
            {
                if (id==item.Shopid)
                {
                    item.Name = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
                    item.Leixing = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
                    item.Salary = int.Parse(((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text);
                    item.Miaoshu = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
                }
            }
            this.GridView1.EditIndex = -1;
            this.GridView1.DataSource = shops;
            this.GridView1.DataBind();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            this.GridView1.EditIndex = -1;
            this.GridView1.DataSource = shops;
            this.GridView1.DataBind();
        }
    }
}